<?php
/**
 * Created by PhpStorm.
 * User: 式神 (luck48.com)
 * Email: 289650682@qq.com
 * Name: ${NAME}Administrator
 * Date: 2017-03-23
 * Time: 16:01
 */
?>
@extends('admin.layouts')
@section('main')
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--列表-->
                <section class="panel panel-padding">
                    <div class="group-button">
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="id" data-params='{"url": "{{url('admin/categorydel')}}","method":"post","data":"_token={{csrf_token()}}","confirm":"true","confirmTest":{"title":"{{trans('config.message')}}","msg":"{{trans('config.btn_text_delete')}}","btn":["{{trans('config.yes')}}","{{trans('config.no')}}"]} }'>
                            <i class="iconfont">&#xe626;</i> {{trans('config.btn_delete')}}
                        </button>
                        <button class="layui-btn layui-btn-small modal-iframe" data-method="add" data-params='{"content": "{{url('admin/categoryadd')}}", "title":"{{trans('config.add')}}","area":"700px,600px","type":"1"}'>
                            <i class="iconfont">&#xe649;</i> {{trans('config.btn_add')}}
                        </button>
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>
@endsection

@section('script')

    <script id="list-tpl" type="text/html" data-params='{"url":"{{url('admin/categorylist')}}","method":"post","data":{"_token":"{{csrf_token()}}"},"pageid":"#page"}'>
        <table id="example" class="layui-table lay-even">
            <thead>
            <tr>
                <th width="30"><input type="checkbox" id="checkall" data-name="id" lay-filter="check" lay-skin="primary"></th>
                <th width="60">ID</th>
                <th width="200">名称</th>
                <th>显示名称</th>
                <th width="60">排序</th>
                <th width="240">操作</th>
            </tr>
            </thead>
            <tbody>
            <{# layui.each(d.list, function(index, item){ }>
            <tr>
                <td><input type="checkbox" name="id" value="<{item.id}>" lay-skin="primary"></td>
                <td><{item.id}></td>
                <td><{item._cate_name}></td>
                <td><{item.name}></td>
                <td><input type="text" class="layui-input ajax-blur" name="listsort" value="<{item.listsort}>" data-params='{"url":"{{url('admin/categoryedit')}}","data":"id=<{item.id}>&_token={{csrf_token()}}","loading":"false"}'></td>
                <td>
                    <button class="layui-btn layui-btn-mini layui-btn-normal modal-iframe" data-method="addchild" data-params='{"content":"{{url('admin/categoryadd')}}?pid=<{item.id}>","area":"700px,600px", "title": "{{trans('config.btn_add_child')}}","type":"1","shadeClose":1}'>
                        <i class="iconfont">&#xe649;</i>{{trans('config.btn_add_child')}}
                    </button>
                    <button class="layui-btn layui-btn-mini modal-iframe" data-params='{"content": "{{url('admin/categoryedit')}}?id=<{item.id}>","area":"700px,600px", "title": "{{trans('config.edit')}}","type":"1","shadeClose":1}'>
                        <i class="iconfont">&#xe653;</i>{{trans('config.btn_edit')}}
                    </button>
                    <button class="layui-btn layui-btn-mini layui-btn-danger" data-method="del" data-url="{{url('admin/categorydel')}}" data-id="<{item.id}>">
                        <i class="iconfont">&#xe626;</i>{{trans('config.btn_delete')}}
                    </button></td>
                </td>
            </tr>
            <{# }); }>
            </tbody>

        </table>
    </script>



    <script>
        layui.use(['list','jquery'],function(){
            var $= layui.jquery;
            $(document).on('click','.layui-btn', function(){
                var othis = $(this), method = othis.data('method');
                active[method] ? active[method].call(this, othis) : '';
            });
            var active={
                del:function(othis){
                    var url=$(othis).attr('data-url');
                    var id=$(othis).attr('data-id');
                    var yesTest="{{trans('config.yes')}}";
                    var noTest="{{trans('config.no')}}";
                    layer.confirm("{{trans('config.btn_text_delete')}}", {icon: 3, title:"{{trans('config.message')}}"
                        ,btn: [yesTest,noTest]
                    }, function(){
                        $.ajax({
                            url:url,
                            type:"post",
                            data:{"id":id,"_token":"{{csrf_token()}}"},
                            beforeSend:function(){
                                layer.load(1);
                            },
                            success:function(data){
                                if(data.status==200){
                                    layer.msg("{{trans('config.submit_success')}}");
                                    location.reload();
                                }else{
                                    layer.msg("{{trans('config.submit_error')}}");
                                }
                            },
                            complete:function(){
                                layer.closeAll('loading');
                            },
                            error:function(){
                                layer.msg("{{trans('config.net_error')}}");
                            }
                        })
                    }, function(){
                    });
                }
            }
        })
    </script>
@endsection
